<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <p><button onclick="btn_color()">点击将3个盒子变为红色</button></p>
        <div class="box1">
            <div id="case"></div>
            <div id="case"></div>
            <div id="case"></div>
        </div>
    </div>
</body>
<script>
    //新学知识  querySelectorAll('#case') 可以获取回来所有id为case的盒子
    let zsc = document.querySelectorAll('#case')
    
    //for 循环
    function btn_color() {
        for (let i = 0; i < zsc.length; i++) {
            zsc[i].style.background = 'red'
        }
    }
</script>

</html>
<style>
    .box {
        width: 600px;
        margin: auto;
        text-align: center;
    }
    
    .box1 {
        margin: auto;
        width: 600px;
        display: flex;
        justify-content: space-around;
    }
    
    .box1>div {
        width: 100px;
        height: 100px;
        background-color: black;
    }
</style>